﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UniMana.Utils.Controls;
using System.Windows.Forms;
using System.Data;
using UniMana.Data;
using System.Data.Linq;

namespace UniMana.Data
{
    public static class Training_SubjectRelationshipData
    {
        /// <summary>
        /// Lấy các môn quan hệ
        /// </summary>
        /// <param name="nSubjectRelationship"></param>
        /// <param name="nSubject"></param>
        /// <param name="_iSubjectKey">Mã môn</param>
        /// <returns></returns>
        public static IQueryable GetListBySubjectKey(this Table<Training_SubjectRelationship> nSubjectRelationship, Table<Training_Subject> nSubject, int _iSubjectKey)
        {
            var iQuery = from t in nSubjectRelationship
                         join t0 in nSubject on new { Training_SubjectKey2 = Convert.ToInt32(t.Training_SubjectKey2) } equals new { Training_SubjectKey2 = t0.Training_SubjectKey }
                         where
                           t.Training_SubjectKey1 == _iSubjectKey
                         select new
                         {
                             t.Training_SubjectRelationshipKey,
                             t.Training_SubjectKey1,
                             Training_SubjectKey2 = (System.Int32?)t.Training_SubjectKey2,
                             t0.ID,
                             t0.Name,
                             t.Relationship,
                             t0.Catalogue_DepartmentKey,
                             t0.Note,
                             t0.Credits1,
                             t0.Credits2,
                             t0.Credits3,
                             t0.Credits4,
                             t0.TotalCredits
                         };
            return iQuery;
        }
    }
}
